/*
 * @Date: 2021-08-15 23:11:38
 * @LastEditors: Wangjun
 * @LastEditTime: 2021-12-07 22:03:25
 * @FilePath: \analysise:\go\src\gitee.com\haodreams\lua\luatask\boss.go
 * @Description:
 */
package luatask

import (
	"sync"

	"github.com/robfig/cron"
	lua "github.com/yuin/gopher-lua"
)

var boss *Boss = new(Boss)

func init() {
	boss.init()
}

type Boss struct {
	kv        map[string]lua.LValue
	SyncTask  SyncTask
	AsyncTask AsyncTask
	asyncCron *cron.Cron
	syncCron  *cron.Cron
	kvLock    sync.RWMutex
}

//GetLuadbBoss 获取管理boss
func GetTasks() *Boss {
	return boss
}

func (m *Boss) init() {
	m.kv = map[string]lua.LValue{}

	// InitSyncLua("lua/", cb)
	// InitAsynLua("lua/", cb)
}

//Set .
func (m *Boss) Set(key string, value lua.LValue) {
	m.kvLock.Lock()
	defer m.kvLock.Unlock()
	m.kv[key] = value
}

//Get .
func (m *Boss) Get(key string) lua.LValue {
	m.kvLock.RLock()
	defer m.kvLock.RUnlock()
	return m.kv[key]
}
